using Game.Main.Model;
using Game.XH;
using SimpleJSON;

namespace Game.Component
{
	public class TouchMoveItem : BaseItem
	{
		private float MAX_MODEL_Y;

		private float MIN_MODEL_Y;

		private float lastTouchY;

		private float modelY;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			string[] array = data.itemData.scriptParams.Split(',');
			if (array.Length == 2)
			{
				MIN_MODEL_Y = float.Parse(array[0]);
				MAX_MODEL_Y = float.Parse(array[1]);
			}
			else
			{
				Trace.LogError(base.itemData.id + "配置错误");
			}
			SetModelY(data.modelY);
		}

		private void SetModelY(float val)
		{
			if (val > MAX_MODEL_Y)
			{
				val = MAX_MODEL_Y;
			}
			else if (val < MIN_MODEL_Y)
			{
				val = MIN_MODEL_Y;
			}
			modelY = val;
			model.SetLocalY(modelY);
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			lastTouchY = touchEventData.curPos.y;
		}

		public override void TouchMove(TouchEventData touchEventData)
		{
			SetModelY(model.localPosition.y + touchEventData.curPos.y - lastTouchY);
			lastTouchY = touchEventData.curPos.y;
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["39"] = modelY.ToString("F3");
		}
	}
}
